home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / syntax / dosbatch.vim < prev    next >
Encoding:
Text File  |  2001-09-02  |  5.8 KB  |  156 lines

  1. " Vim syntax file
  2. " Language:    MSDOS batch file (with NT command extensions)
  3. " Maintainer:    Mike Williams <mrw@netcomuk.co.uk>
  4. " Filenames:    *.bat
  5. " Last Change:    13th July 2001
  6. " Web Page:     N/A
  7. "
  8. " Options Flags:
  9. " dosbatch_cmdextversion    - 1 = Windows NT, 2 = Windows 2000 [default]
  10. "
  11.  
  12. " For version 5.x: Clear all syntax items
  13. " For version 6.x: Quit when a syntax file was already loaded
  14. if version < 600
  15.   syntax clear
  16. elseif exists("b:current_syntax")
  17.   finish
  18. endif
  19.  
  20. " Set default highlighting to Win2k
  21. if !exists("dosbatch_cmdextversion")
  22.   let dosbatch_cmdextversion = 2
  23. endif
  24.  
  25. " DOS bat files are case insensitive but case preserving!
  26. syn case ignore
  27.  
  28. syn keyword dosbatchTodo contained    TODO
  29.  
  30. " Dosbat keywords
  31. syn keyword dosbatchStatement    goto call exit
  32. syn keyword dosbatchConditional    if else
  33. syn keyword dosbatchRepeat    for
  34.  
  35. " Some operators - first lot are case sensitive!
  36. syn case match
  37. syn keyword dosbatchOperator    EQU NEQ LSS LEQ GTR GEQ
  38. syn case ignore
  39. syn match dosbatchOperator      "\s[-+\*/%]\s"
  40. syn match dosbatchOperator      "="
  41. syn match dosbatchOperator      "[-+\*/%]="
  42. syn match dosbatchOperator      "\s\(&\||\|^\|<<\|>>\)=\=\s"
  43. syn match dosbatchIfOperator    "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=2
  44.  
  45. " String - using "'s is a convenience rather than a requirement outside of FOR
  46. syn match dosbatchString    "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,@dosbatchNumber
  47. syn match dosbatchString    "\<echo[^)>|]*"lc=4 contains=dosbatchVariable,dosbatchArgument,@dosbatchNumber
  48. syn match dosbatchEchoOperator  "\<echo\s\+\(on\|off\)\s*$"lc=4
  49.  
  50. " For embedded commands
  51. syn match dosbatchCmd        "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator
  52.  
  53. " Numbers - surround with ws to not include in dir and filenames
  54. syn match dosbatchInteger       "[[:space:]=(/:]\d\+"lc=1
  55. syn match dosbatchHex        "[[:space:]=(/:]0x\x\+"lc=1
  56. syn match dosbatchBinary    "[[:space:]=(/:]0b[01]\+"lc=1
  57. syn match dosbatchOctal        "[[:space:]=(/:]0\o\+"lc=1
  58. syn cluster dosbatchNumber      contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
  59.  
  60. " Command line switches
  61. syn match dosbatchSwitch    "/\(\a\+\|?\)"
  62.  
  63. " Various special escaped char formats
  64. syn match dosbatchSpecialChar   "\^[&|()<>^]"
  65. syn match dosbatchSpecialChar   "\$[a-hl-npqstv_$+]"
  66. syn match dosbatchSpecialChar   "%%"
  67.  
  68. " Environment variables
  69. syn match dosbatchIdentifier    contained "\s\h\w*\>"
  70. syn match dosbatchVariable    "%\h\w*%"
  71. syn match dosbatchVariable    "%\h\w*:\*\=[^=]*=[^%]*%"
  72. syn match dosbatchVariable    "%\h\w*:\~\d\+,\d\+%" contains=dosbatchInteger
  73. syn match dosbatchSet        "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
  74.  
  75. " Args to bat files and for loops, etc
  76. syn match dosbatchArgument    "%\(\d\|\*\)"
  77. syn match dosbatchArgument    "%%[a-z]\>"
  78. if dosbatch_cmdextversion == 1
  79.   syn match dosbatchArgument    "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
  80. else
  81.   syn match dosbatchArgument    "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
  82. endif
  83.  
  84. " Line labels
  85. syn match dosbatchLabel        "^\s*:\s*\h\w*\>"
  86. syn match dosbatchLabel        "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
  87. syn match dosbatchLabel        "\<goto\s\+\h\w*\>"lc=4
  88. syn match dosbatchLabel        ":\h\w*\>"
  89.  
  90. " Comments - usual rem but also two colons as first non-space is an idiom
  91. syn match dosbatchComment    "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
  92. syn match dosbatchComment    "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
  93. syn match dosbatchComment    "\s*:\s*:.*$" contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
  94.  
  95. " Comments in ()'s - still to handle spaces before rem
  96. syn match dosbatchComment    "(rem[^)]*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
  97.  
  98. syn keyword dosbatchImplicit    append assoc at attrib break cacls cd chcp chdir
  99. syn keyword dosbatchImplicit    chkdsk chkntfs cls cmd color comp compact convert copy
  100. syn keyword dosbatchImplicit    date del dir diskcomp diskcopy doskey echo endlocal
  101. syn keyword dosbatchImplicit    erase fc find findstr format ftype
  102. syn keyword dosbatchImplicit    graftabl help keyb label md mkdir mode more move
  103. syn keyword dosbatchImplicit    path pause popd print prompt pushd rd recover rem
  104. syn keyword dosbatchImplicit    ren rename replace restore rmdir set setlocal shift
  105. syn keyword dosbatchImplicit    sort start subst time title tree type ver verify
  106. syn keyword dosbatchImplicit    vol xcopy
  107.  
  108. " Define the default highlighting.
  109. " For version 5.7 and earlier: only when not done already
  110. " For version 5.8 and later: only when an item doesn't have highlighting yet
  111. if version >= 508 || !exists("did_dosbatch_syntax_inits")
  112.   if version < 508
  113.     let did_dosbatch_syntax_inits = 1
  114.     command -nargs=+ HiLink hi link <args>
  115.   else
  116.     command -nargs=+ HiLink hi def link <args>
  117.   endif
  118.  
  119.   HiLink dosbatchTodo        Todo
  120.  
  121.   HiLink dosbatchStatement    Statement
  122.   HiLink dosbatchCommands    dosbatchStatement
  123.   HiLink dosbatchLabel        Label
  124.   HiLink dosbatchConditional    Conditional
  125.   HiLink dosbatchRepeat        Repeat
  126.  
  127.   HiLink dosbatchOperator       Operator
  128.   HiLink dosbatchEchoOperator   dosbatchOperator
  129.   HiLink dosbatchIfOperator     dosbatchOperator
  130.  
  131.   HiLink dosbatchArgument    Identifier
  132.   HiLink dosbatchIdentifier     Identifier
  133.   HiLink dosbatchVariable    dosbatchIdentifier
  134.  
  135.   HiLink dosbatchSpecialChar    SpecialChar
  136.   HiLink dosbatchString        String
  137.   HiLink dosbatchNumber        Number
  138.   HiLink dosbatchInteger    dosbatchNumber
  139.   HiLink dosbatchHex        dosbatchNumber
  140.   HiLink dosbatchBinary        dosbatchNumber
  141.   HiLink dosbatchOctal        dosbatchNumber
  142.  
  143.   HiLink dosbatchComment    Comment
  144.   HiLink dosbatchImplicit    Function
  145.  
  146.   HiLink dosbatchSwitch        Special
  147.  
  148.   HiLink dosbatchCmd        PreProc
  149.  
  150.   delcommand HiLink
  151. endif
  152.  
  153. let b:current_syntax = "dosbatch"
  154.  
  155. " vim: ts=8
  156.